package com.xsoft;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.sun.org.apache.bcel.internal.generic.NEW;



public class TestMyMongodb {
	private static final String uuid = "8f6bc3f1-0314-4a89-b7e5-16dc5b7d1109";
	private static final String db_name="db/my_mongodb.xml";
	
	public static void main(String[] args) {
		//new TestMyMongodb().createDataBase();//创建数据库
//		new TestMyMongodb().insertData();//插入数据
//		new TestMyMongodb().updateData();//修改数据
		//new TestMyMongodb().deleteData();//删除数据
		new TestMyMongodb().listAll();//获取表的全部数据
		
		
	}

	/**
	 * 创建数据库
	 */
	private void createDataBase() {
		try {
			MyMongodb dao = new MyMongodb();
			dao.createDataBase(db_name);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	/**
	 * 插入数据
	 */
	private void insertData() {
		Car car = new Car();
		car.setBrand("Ford");
		car.setModel("focus");
		car.setPower(100);
		car.setPrice(10680.88);
		car.setProductDate(new Date());
		
		try {
			MyMongodb dao = new MyMongodb();
			dao.addData(db_name, "test", car);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 修改数据
	 */
	private void updateData() {
		Car car = new Car();
		car.set_uuid(uuid);
		car.setBrand("Land Rover");
		car.setModel("discovery");
		car.setPower(200);
		car.setPrice(106800.88);
		car.setProductDate(new Date());
		
		try {
			MyMongodb dao = new MyMongodb();
			dao.updateData(db_name, "test", car);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 删除数据
	 */
	private void deleteData() {
		Car car= new Car();
		car.set_uuid(uuid);
		
		try {
			MyMongodb dao = new MyMongodb();
			dao.deleteData(db_name, "test", car);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 获取表的全部数据
	 */
	private void listAll() {
		try {
			MyMongodb dao = new MyMongodb();
			List<Map> maps=dao.loadTableDatas(db_name, "test");
			System.out.println(maps.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
